package com.ruoyi.factory.bom.controller.system;

import com.ruoyi.factory.bom.domain.BomData;
import com.ruoyi.factory.bom.service.IDataHandleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName DataTransferController
 * @Author LiuJiaji
 * @Date 2022/10/24 11:11
 * @Description: TODO 数据处理
 **/
@EnableScheduling
@Controller
public class DataHandleController {

    @Autowired
    private IDataHandleService dataHandleService;

    protected final Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * @author: Liujiaji 
     * @date: 2022/10/24 11:16
     * @description: TODO 数据迁移 更新bom数据到本地,同时更新成本库
     * @param: [s]
     * @return: void
     **/
//    @Scheduled(cron = "0 0/5 * * * ?")
//    @PostConstruct
    public void dataTransfer(){
        logger.info("定时器执行了------");
        System.out.println("定时器执行了------");
        dataHandleService.dataTransfer();
    }

//
//    public static void main(String[] args) {
//        try {
//            Class.forName("com.mysql.jdbc.Driver");
//            //查询bom数据,处理数据存入本地
//            Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/rf_system?useSSL=false", "root", "root");
//
///*
//            String sql="UPDATE Stu set money = money + 2000 where id =2";
//            Statement stat = conn.createStatement();
//            int count = stat.executeUpdate(sql);
//            System.out.println(count);
//            */
//
//            String sql = "select * from t_bom_data";
//            Statement stmt = conn.createStatement();
//            ResultSet rs = stmt.executeQuery(sql);
//
//            while(rs.next()){
//                BomData bomData = new BomData();
//                bomData.setBomname(rs.getString("BOMNAME"));
//                bomData.setBomvar(rs.getString("BOMVAR"));
//                bomData.setSeqnum(rs.getString("SEQNUM"));
//                bomData.setParentid(rs.getString("PARENTID"));
//                bomData.setFatherpartvar(rs.getString("FATHERPARTVAR"));
//                bomData.setPartid(rs.getString("PARTID"));
//                bomData.setNodeExistMode(rs.getString("NODE_EXIST_MODE"));
//
//                bomData.setAssemblelevel(rs.getString("ASSEMBLELEVEL"));
//                bomData.setPartvar(rs.getString("PARTVAR"));
//                bomData.setSupplystate(rs.getString("SUPPLYSTATE"));
//                bomData.setCounts(rs.getString("COUNTS"));
//                bomData.setAssembleproctime(rs.getString("ASSEMBLEPROCTIME"));
//                bomData.setVirtualpart(rs.getString("VIRTUALPART"));
//                bomData.setValidtime(rs.getString("VALIDTIME"));
//                bomData.setInvalidtime(rs.getString("INVALIDTIME"));
//                bomData.setIsreference(rs.getString("ISREFERENCE"));
//                bomData.setOperation(rs.getString("OPERATION"));
//                bomData.setFrezonbombackup2(rs.getString("FREZONBOMBACKUP2"));
//                bomData.setFrezonbombackup3(rs.getString("FREZONBOMBACKUP3"));
//                bomData.setChinaname(rs.getString("CHINANAME"));
//                bomData.setTotalweight(rs.getString("TOTALWEIGHT"));
//                bomData.setAutostat(rs.getString("AUTOSTAT"));
//                bomData.setNodeExistMode1(rs.getString("NODE_EXIST_MODE"));
//                bomData.setNodetimestamp(rs.getString("NODETIMESTAMP"));
//            }
//            rs.close();
//            conn.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
    
}
